import  json
from qmt_tool.path_tool import CPathTool
def write_json(file_path, data):
    with open(file_path, 'w',encoding='utf-8') as json_file:
        json.dump(data, json_file,ensure_ascii=False, indent=4)

# 读取JSON文件
def read_json(file_path):
    with open(file_path, 'r',encoding='utf-8') as json_file:
        data = json.load(json_file)
    return data


def get_config_hold_monitor_file():
    #取持仓监控部分参数
    filepath=CPathTool().get_project_root_path()/'config_file/hold_monitor.json'
    file_dict=read_json(filepath)
    return file_dict


def get_config_signal_file(): #取交易的配置文件
    filepath=CPathTool().get_project_root_path()/'config_file/signal_config.json'
    file_dict=read_json(filepath)
    return file_dict

def save_config_signal_file(data_dict): #取交易的配置文件
    filepath=CPathTool().get_project_root_path()/'config_file/signal_config.json'
    file_dict=write_json(filepath,data_dict)
    return file_dict

def save_config_trade_file(data_dict): #取交易的配置文件
    filepath=CPathTool().get_project_root_path()/'config_file/trade_config.json'
    file_dict=write_json(filepath,data_dict)
    return file_dict

def get_config_trade_file(): #取交易的配置文件
    filepath=CPathTool().get_project_root_path()/'config_file/trade_config.json'
    file_dict=read_json(filepath)
    return file_dict



def get_config_jsl_file(): #取交易的配置文件
    filepath=CPathTool().get_project_root_path()/'config_file/jisilu_account.json'

    file_dict=read_json(filepath)
    return file_dict

def get_config_data_download_file(): #取交易的配置文件
    filepath=CPathTool().get_project_root_path()/'config_file/data_download.json'
    file_dict=read_json(filepath)
    return file_dict

def save_config_data_download_file(data_dict): #取交易的配置文件
    filepath=CPathTool().get_project_root_path()/'config_file/data_download.json'
    file_dict=write_json(filepath,data_dict)
    return file_dict



def get_conf_tongdaxin_file():
    filepath=CPathTool().get_project_root_path()/'config_file/tongdaxin.json'
    file_dict=read_json(filepath)
    return file_dict

def get_conf_database_file():
    filepath=CPathTool().get_project_root_path()/'config_file/database.json'
    file_dict=read_json(filepath)
    return file_dict